package com.yungu.swift.api.route.v2.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.common.service.CommonSmsService;
import com.yungu.swift.utils.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.yungu.swift.api.config.NacosListener.SYS_CONFIG;

/**
 * @author : cuixiuyin
 * @date : 2019/11/18
 */
@RestController(value = "CommonSmsApiV2")
@RequestMapping("/api/v2/common/sms")
@Api(value = "系统通用短信接口V2", tags = "系统通用短信接口V2版本")
public class CommonSmsApi {


    @Reference
    private CommonSmsService commonSmsService;

    @RequestMapping(value = {"/message/send"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "通用发送短信内容", response = ResponseData.class)
    public ResponseData<Boolean> sendContent(@RequestBody Map<String, String> paramMap) {
        String mobile = paramMap.get("mobile");
        String message = paramMap.get("message");
        if (ParamUtil.isIllegal(mobile, message)) {
            return ResponseData.buildErrorResponse(ResponseData.ERROR_CODE, "参数异常");
        }
        return commonSmsService.sendCommon(mobile, message, SYS_CONFIG.getAppid());
    }
}
